/**
 * Copyright (c) 2015-2016, Chill Zhuang 庄骞 (smallchill@163.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ikkong.biz.controller;

import com.ikkong.biz.model.AsyncResult;
import com.ikkong.core.dao.Blade;
import com.ikkong.core.jfinal.ext.kit.JsonKit;
import com.ikkong.core.toolbox.Record;
import com.ikkong.qy.util.WeixinApi;
import com.ikkong.system.controller.base.AdminBaseController;
import com.ikkong.system.meta.intercept.DeptIntercept;
import com.ikkong.system.model.Dept;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.ehcache.CacheKit;

public class AsyncController extends AdminBaseController{
	private static String BASE_PATH = "/biz/async/";
	
	public void index() {
		AsyncResult async = Blade.create(AsyncResult.class).findFirst("select * from tb_async_result ar where ar.type = 'contact'", null);
		setAttr("result", async);		
		
		setAttr("token", WeixinApi.getEnableToken());
		
		render(BASE_PATH + "index.html");
	}
	
	public void start(){
		new Thread(){
			@Override
			public void run() {
				WeixinApi.syncData();
			}
		}.start();
		renderJson(success("成功"));
	}
	
}
